Skip to content

fix(r3d): check decode status, validate clip geometry, report errors - #5413

Merged
lgritz merged 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-r3d
Oct 21, 2026
Merged

lgritz merged 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-r3d

Conversation

@lgritz

@lgritz lgritz commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Changes suggeted by a security audit of the R3D reader.

read_frame() ignored the DecodeVideoFrame() status and marked the frame read regardless. On failure the output buffer keeps whatever was there - stale pixels from an earlier frame, or, for the first frame, uninitialized heap from aligned_malloc - and read_native_scanline() copied it out and returned success. Track whether a frame actually decoded and hard-error if not.

The clip width, height and frame count went straight into the ImageSpec and the buffer size math with no range check, and the ImageSpec narrowed them to int while the buffer used the untruncated size_t, so the two could disagree about how big a frame is. Range-check all three, run the spec through check_open() and check_compression_ratio(), and take the buffer size from the validated spec.

If InitializeSdk() failed, the SDK was finalized inside initialize() but open() went on to construct an R3DSDK::Clip against a torn-down SDK, and the destructor finalized a second time. Track the init result and fail open() cleanly.

Every open() failure path returned false with no errorfmt(), so callers got a failure with an empty error message. All of them now report.

Also promote the scanline offset arithmetic to imagesize_t since nchannels * width * y overflows int on a large enough frame.

I could not verify this, since I don't have the R3D SDK. I will need this verified in review.

Assisted-by: Claude Code / claude-opus-5

@lgritz

lgritz commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

@1div0 I would appreciate if you could review and test this, since I don't have the R3D SDK on my end to make it build this file.

@lgritz

lgritz commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

@1div0 Ping on this, if you could take a look, please.

@1div0

1div0 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

pong

Today.

Changes suggeted by a security audit of the R3D reader.

read_frame() ignored the DecodeVideoFrame() status and marked the frame read
regardless. On failure the output buffer keeps whatever was there - stale
pixels from an earlier frame, or, for the first frame, uninitialized heap
from aligned_malloc - and read_native_scanline() copied it out and returned
success. Track whether a frame actually decoded and hard-error if not.

The clip width, height and frame count went straight into the ImageSpec and
the buffer size math with no range check, and the ImageSpec narrowed them to
int while the buffer used the untruncated size_t, so the two could disagree
about how big a frame is. Range-check all three, run the spec through
check_open() and check_compression_ratio(), and take the buffer size from the
validated spec.

If InitializeSdk() failed, the SDK was finalized inside initialize() but
open() went on to construct an R3DSDK::Clip against a torn-down SDK, and the
destructor finalized a second time. Track the init result and fail open()
cleanly.

Every open() failure path returned false with no errorfmt(), so callers got a
failure with an empty error message. All of them now report.

Also promote the scanline offset arithmetic to imagesize_t;
`nchannels * width * y` overflows int on a large enough frame.

I could not verify this, since I don't have the R3D SDK. I will need
this verified in review.

Assisted-by: Claude Code / claude-opus-5

Signed-off-by: Larry Gritz <lg@larrygritz.com>

@1div0 1div0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK.

ThanX

@lgritz
lgritz merged commit febb174 into AcademySoftwareFoundation:main Oct 21, 2026
30 checks passed
@lgritz
lgritz deleted the lg-r3d branch October 22, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants